<?php
include('../../inc/global.inc');
include("../islogin.php");
$url=$_SERVER['HTTP_REFERER'];
?>
<?php
if($_POST[act_tj]){
  $cat_tj=($_POST[cat_tj])?$_POST[cat_tj]:0;
  @mysql_query("insert into pf_catalog (cat_name,cat_id,cat_tj) values ('$_POST[cat_name]','$_POST[cat_id]','$cat_tj')");
echo "<script>location='".$_POST[url]."';</script>";
}
?>
<?php
if($_POST['act_xg']){
  $cat_tj=($_POST[cat_tj])?$_POST[cat_tj]:0;
  @mysql_query("update pf_catalog set cat_name='$_POST[cat_name]',cat_id='$_POST[cat_id]',cat_tj='$cat_tj' where id='".$_POST['iid']."'");
echo "<script>location='".$_POST[url]."';</script>";
}
?>
<HTML>
<HEAD>
<TITLE>Admin</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK href="../css/css.css" rel=stylesheet>
<script type='text/javascript' src="../js/islogin.js" charset="gb2312"></script>
</HEAD>
<BODY>
<center>
  <table width="600" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
    <tr>
      <td height="25" bgcolor="#EEEEF9" style="padding-left:5px;">添加、修改批发目录&nbsp;&nbsp;<a href="javascript:history.go(-1)">返回</a></td>
    </tr>
  </table>
<?php
if($_GET[tj]){
?>
  <table width="600" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
  <form method="post" action="catalog_modify.php" onSubmit="return check()" name="form1">
    <tr>
      <td height="30" colspan="2" align="center" bgcolor="#8DA8CF">添加批发目录</td>
    </tr>
    <tr>
      <td width="22%" height="30" align="center" bgcolor="#FFFFFF">批发目录名称</td>
      <td width="78%" align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input name="cat_name" type="text" id="cat_name" size="30" maxlength="100"></td>
    </tr>
	 <tr>
      <td height="30" align="center" bgcolor="#FFFFFF">上级目录</td>
      <td align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><select name="cat_id">
  <option value="0" selected>--选择上级目录--</option>
  <?php
  $sql="select * from pf_catalog where cat_id=0 order by id asc";
  $rs=mysql_query($sql);
  while($row=mysql_fetch_array($rs)){
  ?><option value="<?=$row['id']?>" <?php if($_GET[id]==$row['id']){echo "selected";}?>><?=$row[cat_name]?></option>
       <?php
         $sql2="select * from pf_catalog where cat_id='".$row['id']."' order by id asc";
		 $rs2=mysql_query($sql2);
		 while($row2=mysql_fetch_array($rs2)){
       ?><option value="<?=$row2['id']?>" <?php if($_GET[id]==$row2[id]){echo "selected";}?>>&nbsp;&nbsp;&nbsp;&nbsp;|--<?=$row2[cat_name]?></option>
  <?php
  }}
  ?>
      </select></td>
    </tr>
    <tr>
      <td width="22%" height="30" align="center" bgcolor="#FFFFFF">是否推荐</td>
      <td width="78%" align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input type="radio" name="cat_tj" value="1">是&nbsp;<input name="cat_tj" type="radio" value="0" checked>
        否</td>
    </tr>
    <tr><input type="hidden" name="url" value="<?=$url?>">
	<input type="hidden" name="act_tj" value="ok">
      <td height="30" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" value="提交"></td>
    </tr>
	</form>
  </table>
<?php }?>
  <?php
if($_GET['xg']){
$sql="select * from pf_catalog where id=".$_GET['xg_id'];
$rs=mysql_query($sql);
$row=mysql_fetch_array($rs)
?>
<table width="600" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
    <form method="post" action="catalog_modify.php" onSubmit="return check()" name="form1">
      <tr>
        <td height="30" colspan="2" align="center" bgcolor="#8DA8CF">修改批发目录</td>
      </tr>
      <tr>
        <td width="22%" height="30" align="center" bgcolor="#FFFFFF">批发目录名称</td>
        <td width="78%" align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input name="cat_name" type="text" value="<?=$row[cat_name]?>" size="30" maxlength="100"></td>
      </tr>
      <tr>
        <td height="30" align="center" bgcolor="#FFFFFF">上级目录</td>
        <td align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><select name="cat_id">
            <option value="0">--选择上级目录--</option>
  <?php
  $sql2="select * from pf_catalog where cat_id=0 order by id asc";
  $rs2=mysql_query($sql2);
  while($row2=mysql_fetch_array($rs2)){
  ?>
          <option value="<?=$row2['id']?>" <?php if($row2[id]==$row[cat_id]){echo "selected";}?>><?=$row2[cat_name]?></option>
  <?php
         $sql3="select * from pf_catalog where cat_id='".$row2[id]."' order by cat_name asc";
		 $rs3=mysql_query($sql3);
		 while($row3=mysql_fetch_array($rs3)){
       ?><option value="<?=$row3['id']?>" <?php if($row3[id]==$row[cat_id]){echo "selected";}?>>&nbsp;&nbsp;&nbsp;&nbsp;|--<?=$row3[cat_name]?></option>
  <?php
  }
  mysql_free_result($rs3);
  }
  mysql_free_result($rs2);
  ?>
        </select></td>
      </tr>
    <tr>
      <td width="22%" height="30" align="center" bgcolor="#FFFFFF">是否推荐</td>
      <td width="78%" align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input type="radio" name="cat_tj" value="1" <?php if($row[cat_tj]==1){echo "checked";}?>>是&nbsp;<input name="cat_tj" type="radio" value="0" <?php if($row[cat_tj]==0){echo "checked";}?>>
        否</td>
    </tr>
      <tr><input type="hidden" name="url" value="<?=$url?>">
        <input type="hidden" name="act_xg" value="ok"><input type="hidden" name="iid" value="<?=$row['id']?>">
        <td height="30" colspan="2" align="center" bgcolor="#FFFFFF"><input name="submit" type="submit" value="提交"></td>
      </tr>
    </form>
  </table>
  <?php
}?>
<br>
</center>
</BODY>
</HTML>
